<?php
namespace Home\Controller;
use Think\Controller;


class OrderController extends Controller {

  //下订单
	function  addorder(){
		$order=M("Order");
        //订单信息
        $num=$_POST["num"];
        $goodsname=$_POST["goodsname"];
        $goodsprice=$_POST["goodsprice"];
        $goodsimage=$_POST["goodsimage"];
        $goodsdesc=$_POST["goodsdesc"];
        $linkman=$_POST["linkman"];
        $address=$_POST["address"];
        $goodsnum=$_POST["goodsnum"];
        $allprice=$_POST["allprice"];
		$time=date('Y-m-d H:i:s',time());
		$complement=$_POST["complement"];
		$buyid=$_POST["buyid"];
		$sellerid=$_POST["sellerid"];

		$data["order_num"]=$num;
		$data["order_goodsname"]=$goodsname;
		$data["order_goodsprice"]=$goodsprice;
		$data["order_goodsimage"]=$goodsimage;
		$data["order_goodsdesc"]=$goodsdesc;
		$data["order_linkman"]=$linkman;
		$data["order_address"]=$address;
		$data["order_goodsnum"]=$goodsnum;
		$data["order_allprice"]=$allprice;
		$data["order_time"]=$time;
		$data["order_complement"]=$complement;
		$data["order_buyid"]=$buyid;
		$data["order_sellerid"]=$sellerid;
		$data["oorderstate"]=0;

		 $result=$order->add($data);
		 
		 if ($result) {
		     $this->ajaxReturn(array(
		        "code"=>200,
		        "message"=>"发布成功!",
                "result"=>$result
		        ),"JSON");
		 }
		 else{
		     $this->ajaxReturn(array(
		        "code"=>500,
		        "message"=>"发布失败！"
		        ),"JSON");
		 }
	}

   //卖家查询供应订单
	function sellerorder(){
      $order=M("Order");
      $sellerid=$_POST["sellerid"];
      $result=$order->where("order_sellerid='$sellerid'")->select();
      	 if ($result) {
		     $this->ajaxReturn(array(
		        "code"=>200,
		        "message"=>"查询成功!",
                "result"=>$result
		        ),"JSON");
		 }
		 else{
		     $this->ajaxReturn(array(
		        "code"=>500,
		        "message"=>"没有对应订单！"
		        ),"JSON");
		 }
	}


   //买家查询购买订单
	function buyorder(){
      $order=M("Order");
      $buyid=$_POST["buyid"];
      $result=$order->where("order_buyid='$buyid'")->select();
      	 if ($result) {
		     $this->ajaxReturn(array(
		        "code"=>200,
		        "message"=>"查询成功!",
                "result"=>$result
		        ),"JSON");
		 }
		 else{
		     $this->ajaxReturn(array(
		        "code"=>500,
		        "message"=>"没有对应订单！"
		        ),"JSON");
		 }
	}

   //买家取消订单
	function Cancleorder(){
		$order=M("Order");
		$orderid=$_POST["orderid"];
		$result=$order->where("order_id='$orderid'")->delete();

         if ($result) {
		     $this->ajaxReturn(array(
		        "code"=>200,
		        "message"=>"取消成功!"
		        ),"JSON");
		 }
		 else{
		     $this->ajaxReturn(array(
		        "code"=>500,
		        "message"=>"取消失败！"
		        ),"JSON");
		 } 

	}


   //卖家确认发货
	function sellerDeliverorder(){
      $order=M("Order");
      $orderid=$_POST["orderid"];
      $data["order_id"]=$orderid;
      $data["oorderstate"]=1;
      $result=$order->save($data);
      	 if ($result) {
		     $this->ajaxReturn(array(
		        "code"=>200,
		        "message"=>"确认发货!"
		        ),"JSON");
		 }
		 else{
		     $this->ajaxReturn(array(
		        "code"=>500,
		        "message"=>"发货失败！"
		        ),"JSON");
		 }
	}









}